package com.isoft.mapper;

import com.isoft.entity.DfmeFettEntity;
import org.apache.ibatis.annotations.*;

@Mapper
public interface DfmeFettMapper {
    @Insert("INSERT INTO MSG_META(SENDER, RECEIVER, SEQUENCE_NUMBER, DATE_TIME, MSG_TYPE, SUB_TYPE) " +
            "VALUES(" +
            "#{meta.sender,jdbcType=VARCHAR}, " +
            "#{meta.receiver,jdbcType=VARCHAR}, " +
            "#{meta.sequenceNumber,jdbcType=NUMERIC}, " +
            "TO_TIMESTAMP(#{meta.dateTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss'), " +
            "#{meta.type,jdbcType=VARCHAR}, " +
            "#{meta.subType,jdbcType=VARCHAR})")
    @Options(useGeneratedKeys = true, keyProperty = "msgId", keyColumn = "MSG_ID")
    void insertMeta(DfmeFettEntity entity);

    @Insert("INSERT INTO FLIGHT_BASE(FLIGHT_ID, FLIGHT_FILE_ID, FLIGHT_IDENTIFIER) " +
            "VALUES(" +
            "#{dflt.flightId,jdbcType=NUMERIC}, " +
            "#{dflt.flightFileId,jdbcType=VARCHAR}, " +
            "#{dflt.flightIdentifier,jdbcType=VARCHAR})")
    int insertFlightBase(DfmeFettEntity entity);

    @Update("UPDATE FLIGHT_ROUTE " +
            "SET ESTIMATED_TIME = TO_TIMESTAMP(#{dflt.estimatedTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss') " +
            "WHERE FLIGHT_ID = #{dflt.flightId} AND AIRPORT_SEQ = " +
            "(SELECT MAX(AIRPORT_SEQ) FROM FLIGHT_ROUTE WHERE FLIGHT_ID = #{dflt.flightId})")
    int updateFlightRoute(DfmeFettEntity entity);
}